package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.OaOrg;
import com.ruoyi.system.service.IOaOrgService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * OA组织机构 信息操作处理
 * 
 * @author ruoyi
 * @date 2020-03-10
 */
@Controller
@RequestMapping("/system/oaOrg")
public class OaOrgController extends BaseController
{
    private String prefix = "system/oaOrg";
	
	@Autowired
	private IOaOrgService oaOrgService;
	
	@RequiresPermissions("system:oaOrg:view")
	@GetMapping()
	public String oaOrg()
	{
	    return prefix + "/oaOrg";
	}
	
	/**
	 * 查询OA组织机构列表
	 */
	@RequiresPermissions("system:oaOrg:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(OaOrg oaOrg)
	{
		startPage();
        List<OaOrg> list = oaOrgService.selectOaOrgList(oaOrg);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出OA组织机构列表
	 */
	@RequiresPermissions("system:oaOrg:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OaOrg oaOrg)
    {
    	List<OaOrg> list = oaOrgService.selectOaOrgList(oaOrg);
        ExcelUtil<OaOrg> util = new ExcelUtil<OaOrg>(OaOrg.class);
        return util.exportExcel(list, "oaOrg");
    }
	
	/**
	 * 新增OA组织机构
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存OA组织机构
	 */
	@RequiresPermissions("system:oaOrg:add")
	@Log(title = "OA组织机构", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(OaOrg oaOrg)
	{		
		return toAjax(oaOrgService.insertOaOrg(oaOrg));
	}

	/**
	 * 修改OA组织机构
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		OaOrg oaOrg = oaOrgService.selectOaOrgById(id);
		mmap.put("oaOrg", oaOrg);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存OA组织机构
	 */
	@RequiresPermissions("system:oaOrg:edit")
	@Log(title = "OA组织机构", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(OaOrg oaOrg)
	{		
		return toAjax(oaOrgService.updateOaOrg(oaOrg));
	}
	
	/**
	 * 删除OA组织机构
	 */
	@RequiresPermissions("system:oaOrg:remove")
	@Log(title = "OA组织机构", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(oaOrgService.deleteOaOrgByIds(ids));
	}
	
}
